#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const int N = 2e5 + 10;
#define INF 0x3f3f3f3f;
typedef long long int ll;
#define close(); std::ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
//----------------------------------------------------------------------------//
int g[110][110], f[110][110], n, m; //到某个点的最大权值
int dx[9] = {0, 0, 0, -1, -1, -1, -2, -2, -3};
int dy[9] = {-1, -2, -3, 0, -1, -2, 0, -1, 0};


int main()
{
    close();
    cin >> n >> m;

    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= m; j++)
        {
            cin >> g[i][j];
            f[i][j] = -INF;
        }
    }

    f[1][1] = g[1][1];
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= m; j++)
        {
            if(i == 1 && j == 1) continue; //起步点不更新

            for(int k = 0; k < 9; k++)
            {
                int x = i + dx[k], y = j + dy[k];
                if(x >= 1 && x <= n && y >= 1 && y <= m)
                {
                    f[i][j] = max(f[i][j], f[x][y] + g[i][j]); //从上一步哪个位置来的
                }
            }
        }
    }

    cout << f[n][m] << '\n';
    return 0;
}
